package com.mdxq.order.controller;


import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mdxq.order.entity.Order;
import com.mdxq.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author WanJl
 * @version 1.0
 * @title OrderController
 * @description
 * @create 2025/2/7
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    @Resource
    private OrderService orderService;

//    @Value("${student.name}")
//    String name;

    //根据订单id查询订单信息
    @GetMapping("/{id}")
    public Order findById(@PathVariable Long id, HttpServletRequest request) {
        String myMsg = request.getHeader("myMsg");
        log.info("请求头--->{}",myMsg);
        Order order = orderService.findById(id);
        log.info("根据订单id查询订单信息---->{}",order);
        return order;
    }
    @SentinelResource("fbId")
    @GetMapping("/findById")
    public Order findById02(@RequestParam("orderId") Long id) {
        Order order = orderService.findById(id);
        return order;
    }

    @GetMapping("/query")
    public Order query() {
        Order order=new Order();
        order.setName("查询订单");
        return order;
    }
    @PostMapping("/update")
    public Order update() {
        Order order=new Order();
        order.setName("修改");
        return order;
    }

    @GetMapping("/queryOrderAndItem")
    public Order queryOrderAndItem(){
        Order order=new Order();
        String s = orderService.queryItem();
        order.setName("查询订单"+s);
        return order;
    }

    @GetMapping("/save")
    public Order save() {
        Order order=new Order();
        String s = orderService.queryItem();
        order.setName("新增订单"+s);
        return order;
    }
}
